Refactor tests of xc module#7475
Merged
Merged
Conversation
added 2 commits
June 16, 2026 22:28
…ion parameters for nspin, domag, domag_z
This commit decouples XC_Functional and related libxc functions from the global PARAM object by adding explicit parameters: 1. Modified XC_Functional::v_xc() to accept nspin, domag, domag_z parameters instead of accessing PARAM 2. Modified XC_Functional::gradcorr() to accept nspin, domag, domag_z parameters 3. Modified XC_Functional::set_xc_type() to accept nspin parameter 4. Modified XC_Functional_Libxc::v_xc_libxc() to accept nspin, domag, domag_z parameters 5. Modified XC_Functional_Libxc::v_xc_meta() to accept nspin parameter Updated all call sites in: - source_estate/module_pot/pot_xc.cpp - source_estate/module_pot/pot_xc_fdm.cpp - source_pw/module_pwdft/forces_cc.cpp - source_pw/module_pwdft/stress_cc.cpp - source_hamilt/module_xc/xc_pot.cpp - source_hamilt/module_xc/libxc_pot.cpp - source_hamilt/module_xc/libxc_abacus.h Updated test files to remove PARAM dependencies: - test_xc3.cpp: Removed PARAM include and initialization - test_xc5.cpp: Removed PARAM include and initialization, updated v_xc, v_xc_meta calls - xctest.h: Removed PARAM include and initialization Default parameter values are provided for backward compatibility.
added 2 commits
June 17, 2026 09:04
…prove parameter passing Summary of changes: 1. Modified libxc_abacus.h: - Removed default value (=1) for nspin parameter in v_xc_libxc - Removed default value (=nullptr) for scaling_factor parameter in v_xc_libxc 2. Modified xc_functional.h: - Changed set_xc_type signature to only accept const std::string xc_func_in - Removed nspin and basis_type parameters from set_xc_type - Removed default parameters from v_xc and gradcorr 3. Modified xc_functional.cpp: - Updated set_xc_type implementation to match new signature - Removed meta-GGA nspin=4 check from set_xc_type (moved to gradcorr) - Removed hybrid functional LCAO check from set_xc_type (no longer needed) - Updated internal set_xc_type calls to use single parameter 4. Modified xc_grad.cpp: - Added meta-GGA nspin=4 check at the beginning of gradcorr function - This is the correct place for runtime validation since nspin is known here 5. Modified xc_pot.cpp: - Updated v_xc_libxc call to pass parameters correctly 6. Modified libxc_pot.cpp: - Updated v_xc_libxc implementation to match new signature 7. Modified stress_gga.cpp: - Changed direct 'true' argument to named variable 'is_stress' for gradcorr call - Improved code readability and maintainability 8. Updated all set_xc_type call sites (12 files): - test_xc.cpp, test_xc1.cpp, test_xc2.cpp, test_xc3.cpp, test_xc5.cpp - xc_functional.cpp, esolver_double_xc.cpp, esolver_ks_lcaopw.cpp - esolver_fp.cpp, Exx_LRI_interface.hpp, xc_kernel.cpp, exx_helper.cpp - All calls now pass only the xc_func_in parameter 9. Updated test_xc3.cpp and test_xc5.cpp: - Added named variables (nspin1, nspin2, nspin4, domag, domag_z, domag_true) - Removed direct numeric literals in function calls Rationale: - Separated functional setup (set_xc_type) from runtime configuration (nspin, basis_type) - Runtime validation checks moved to actual computation functions (gradcorr) - Parameter passing improved with meaningful variable names instead of magic numbers - Code readability and maintainability enhanced - Preparation for future improvements to XC functional interface
zzlinpku
reviewed
Jun 20, 2026
zzlinpku
left a comment
Collaborator
There was a problem hiding this comment.
Code Review: Refactor tests of xc module
This PR decouples v_xc, v_xc_libxc, v_xc_meta, and gradcorr from the global PARAM singleton by passing nspin, domag, domag_z as explicit parameters. This is a solid testability improvement — the #define private public hack is removed and tests no longer mutate global state.
However, two safety checks were removed/moved as side effects, which warrants attention.
See inline comments for details.
zzlinpku
approved these changes
Jun 20, 2026
zzlinpku
left a comment
Collaborator
There was a problem hiding this comment.
Re-reviewed after updates. The multi-line reformatting in stress_gga.cpp looks good — thanks for addressing that. The design choices (meta-GGA check in gradcorr, link-time __EXX guard) are reasonable. LGTM.
maki49
added a commit
to maki49/abacus-develop
that referenced
this pull request
Jun 22, 2026
maki49
added a commit
to maki49/abacus-develop
that referenced
this pull request
Jul 6, 2026
PeizeLin
pushed a commit
that referenced
this pull request
Jul 6, 2026
* initial version of writing H and dH terms (except exx) * correct 1-electron terms: T, Vl, Vnl * fix pot register * Gint_drho * add EXX H&dH, dH (H-F term) of Veff Hartree, and refactor * add dm_container_to_Ds and exx nscf-from-dm workflow; minor refactor OperatorEXX * fix parallel segfaults and kinetic sign * XC H-F term (FD) * enable value-adding HContainers, total dH and atom-specified output; enable nspin=2 * dH test cases * exclude cal_exx_dHs with __EXX_DEV flag, waiting for LibRI PR merged * small fixes * change scf_in_dmr ref due to not renormalizing charge at init_chg==dm * fix conflict #7462 #7475 #7478 * Revert reference change by adding option dm_no_renormalize to init_chg This reverts commit ed14d9f. * fix pyabacus CI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.